/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.chiefmedicalofficer.mcd.model;

import com.hp.hpl.jena.vocabulary.DC;
import com.hp.hpl.jena.vocabulary.RDFS;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

/**
 *
 * @author twilson
 */
public class PropertyDescription {
    private static Logger log = Logger.getLogger(PropertyDescription.class);

    private String subjectUri;
    private String objectUri;
    /**
     * RDFS.label
     */
    private String objectLabel;
    /**
     * DC.title
     */
    private String objectTitle;
    /**
     * DC.description
     */
    private String objectDescription;
    private PredicateDescription predicate;

    public PropertyDescription() {
    }

    public PropertyDescription(String predicateUri, String objectUri) {
        predicate = new PredicateDescription(predicateUri);
        this.objectUri = objectUri;
        GraphStore graphStore = GraphStore.getInstance();
        setObjectTitle(graphStore.getAttribute(objectUri,
                DC.title.getURI()));
        setObjectLabel(graphStore.getAttribute(objectUri,
                RDFS.label.getURI()));
        setObjectDescription(graphStore.getAttribute(objectUri,
                DC.description.getURI()));
    }

    protected void persist() {
        log.setLevel(Level.DEBUG);
        GraphStore graphStore = GraphStore.getInstance();
        log.debug("Persisting triple " + getSubjectUri() + " " +
                getPredicate().getUri() + " " + getObjectUri());
        graphStore.addResourceTriple(
                getSubjectUri(),
                getPredicate().getUri(),
                getObjectUri());
        if (getObjectTitle() != null) {
            graphStore.setAttribute(getObjectUri(),
                    DC.title.getURI(), getObjectTitle());
        }
        if (getObjectLabel() != null) {
            graphStore.setAttribute(getObjectUri(),
                    RDFS.label.getURI(), getObjectLabel());
        }
        if (getObjectDescription() != null) {
            graphStore.setAttribute(getObjectUri(),
                    DC.description.getURI(), getObjectDescription());
        }
    }

    public PredicateDescription getPredicate() {
        return predicate;
    }

    public void setPredicate(PredicateDescription predicate) {
        this.predicate = predicate;
    }

    public String getObjectUri() {
        return objectUri;
    }

    public void setObjectUri(String Uri) {
        this.objectUri = Uri;
    }

    public String getSubjectUri() {
        return subjectUri;
    }

    public void setSubjectUri(String subjectUri) {
        this.subjectUri = subjectUri;
    }

    public String getObjectLabel() {
        return objectLabel;
    }

    public void setObjectLabel(String label) {
        this.objectLabel = label;
    }

    public String getObjectTitle() {
        return objectTitle;
    }

    public void setObjectTitle(String title) {
        this.objectTitle = title;
    }

    public String getObjectDescription() {
        return objectDescription;
    }

    public void setObjectDescription(String description) {
        this.objectDescription = description;
    }

}
